{% extends "layout.html" %}
{% block __data_browser__custom_external_block %}
  <link rel="stylesheet" href="{{ url_for('static', filename="css/customer.css") }}" media="print">
  <script type="text/javascript" src="{{ url_for("static", filename="js/jquery-printarea.js") }}"></script>
  <script type="text/javascript">
    $(function () {
      $("#print").click(function () {
        {% if not receipt.printed %}
          $.post("/cargo/ajax/goods-receipt", {id:{{ receipt.id }}}).success(function (data) {
            $("#printArea").printArea();
          }).error(function (data) {
                if (confirm(data.responseText)) {
                  $("#printArea").printArea();
                }
              });
        {% else %}
          $("#printArea").printArea();
        {% endif %}
      });
    });
  </script>
  <style type="text/css">
    #printArea {
      display: none;
    }

  </style>
{% endblock %}

{% block body %}
  <div class="row">
    <div class="col-lg-6 col-lg-offset-3">
      <h5 class="pull-right">NO. {{ receipt.id }}</h5>
      <table class="table table-striped table-bordered table-condensed">
        <tbody>
        <tr>
          <th colspan="4"><h4 class="text-center">金禾域加工收货单</h4></th>
        </tr>
        <tr>
          <th>收货单号</th>
          <th colspan="3">
            <p class="text-center">{{ receipt.receipt_id }}</p>
          </th>
        </tr>
        <tr>
          <th>公司名称</th>
          <th colspan="3">
            <p class="text-center">{{ receipt.customer.name }}</p>
          </th>
        </tr>
        <tr>
          <th>车辆车牌号</th>
          <th colspan="3"><p
              class="text-center">{{ receipt.unload_session.plate }}</p>
          </th>
        </tr>
        <tr>
          <th>日期</th>
          <th colspan="3">
            <p class="text-center">{{ receipt.create_time }}</p>
          </th>
        </tr>
        <tr>
          <th>产品类型</th>
          <th>产品名称</th>
          <th>净重(公斤)</th>
          <th>交货日期</th>
        </tr>
        {% for entry in receipt.goods_receipt_entries %}
          <tr>
            <td>
              {{ entry.product.product_type.name }}
            </td>
            <td>
              {{ entry.product.name }}
            </td>
            <td>
              {{ entry.weight }}
            </td>
            <td></td>
          </tr>
        {% endfor %}
        <tr>
          <td colspan="2">客户签名:</td>
          <td colspan="2">
            总重量(公斤):{{ receipt.goods_receipt_entries|sum(attribute='weight') }}
          </td>
        </tr>
        </tbody>
      </table>
      <div id="printArea">
        {% for i in range(pages) %}
          <div {% if not loop.last %}class="page-next"{% endif %}>
            <h5 class="pull-right">NO. {{ receipt.id }}</h5>
            <table class="table table-striped table-bordered table-condensed">
              <tbody>
              <tr>
                <th colspan="4"><h4 class="text-center">金禾域加工收货单</h4></th>
              </tr>
              <tr>
                <th>收货单号</th>
                <th colspan="3">
                  <p class="text-center">{{ receipt.receipt_id }}</p>
                </th>
              </tr>
              <tr>
                <th>公司名称</th>
                <th colspan="3">
                  <p class="text-center">{{ receipt.customer.name }}</p>
                </th>
              </tr>
              <tr>
                <th>车辆车牌号</th>
                <th colspan="3"><p
                    class="text-center">{{ receipt.unload_session.plate }}</p>
                </th>
              </tr>
              <tr>
                <th>日期</th>
                <th colspan="3">
                  <p class="text-center">{{ receipt.create_time }}</p>
                </th>
              </tr>
              <tr>
                <th>产品类型</th>
                <th>产品名称</th>
                <th>净重(公斤)</th>
                <th>交货日期</th>
              </tr>
              {% for task in receipt.goods_receipt_entries %}
                {% if loop.index > (i * per_page) and loop.index <= ((i + 1) * per_page) %}
                  <tr>
                    <td>
                      {{ task.product.product_type.name }}
                    </td>
                    <td>
                      {{ task.product.name }}
                    </td>
                    <td>
                      {{ task.weight }}
                    </td>
                    <td></td>
                  </tr>
                {% endif %}
              {% endfor %}
              <tr>
                <td colspan="2">客户签名:</td>
                <td colspan="2">
                  总重量(公斤):{{ receipt.goods_receipt_entries|sum(attribute='weight') }}
                </td>
              </tr>
              </tbody>
            </table>
          </div>
        {% endfor %}
      </div>
      <div class="text-center">
        <button class="btn btn-primary btn-lg" id="print">
          <i class="fa fa-print fa-fw"></i>{{ _("打印") }}
        </button>
        <a href="{{ request.args.get("url") or url_for('goods_receipt.goods_receipt',id_=receipt.id) }}" class="btn btn-lg btn-default">
          <i class="fa fa-step-backward fa-fw"></i>{{ _("返回") }}
        </a>
      </div>
    </div>
  </div>
{% endblock %}

